1 <?php
2 session_start();
3 if(isset($_SESSION['user']))
4 {
5
6 }
7 else{
8 echo"<script>location.href='login.html'</script>";
9 }
10 ?>
11 <!doctype html>
12 <html>
13 <head>
14 <title>Animals </title>
15 <style>
16 body {
17 margin: 0;
18 font-family: Arial, Helvetica, sans-serif;
19 background: #484848;
20 }
21 .topnav {
22 overflow: hidden;
23 background-color: #4CAF50;
24 height: 70px;
25 border: 3px solid green;
26 }
27
28 .topnav a {
29 float: left;
30 color: #f2f2f2;
31 text-align: center;
32 padding: 14px 16px;
33 text-decoration: none;
34 font-size: 35px;
35 font-weight: bold;
36
37 }
38
39 .topnav-right {
40 float: right;
41 }
42 fieldset {
43 background: white;
44 padding: 10px;
45 margin:auto;
46 max-width:593px;
47 box-shadow: 1px 1px 25px rgba(0, 0, 0, 0.35);
48 border-radius: 10px;
49 border: 6px solid #4CAF50;
50
51
52 }
53 </style>
54 </head>
55 <body>
56 <div class="topnav">
57 <a class="active" href="home.html"><img src="ic_add_pet.png"></a>
58 <a href="animals.php">Animals</a>
59 <div class="topnav-right">
60 <a href="logout.php">logout</a>
61 </div>
62 </div>
63 <form>
64 <button type="submit" formaction="animals.php" style="margin:15px;height: 30px;width: 100px;cursor:pointer;border-radius:15px;
65 border: 3px solid green;background-color: #4CAF50;color:#f2f2f2;font-size:17px;">Back</button>
66 </form>
67 <form method="post" action="animalsupdate.php">
68 <fieldset>
69 <input type="text" name="id" placeholder=" Enter pet_id" style="width:100%;height:30px;
70 border: 2px solid #4CAF50; border-radius:3px;background:transparent;" required >
71 <br><br>
72 <input type="text" name="category" placeholder="Enter pet_category" style="width:100%;height:30px;
73 border: 2px solid #4CAF50; border-radius:3px;background:transparent;" required >
74 <br><br>
75
76 <input type="text" name="breed" placeholder="Enter breed" style="width:100%;height:30px;
77 border: 2px solid #4CAF50; border-radius:3px;background:transparent;" required >
78 <br><br>
79 <input type="number" step=any name="weight" placeholder="Enter weight" style="width:280px;height:30px;
80 border: 2px solid #4CAF50; border-radius:3px;background:transparent;" min="1" required >
81
82 <input type="number" step=any name="height" placeholder="Enter height" style="width:300px;height:30px;
83 border: 2px solid #4CAF50; border-radius:3px;background:transparent;" min="15" required >
84 <br><br>
85 <input type="number" name="age" placeholder="Enter age" style="width:280px;height:30px;
86 border: 2px solid #4CAF50; border-radius:3px;background:transparent;" min="1"required >
87
88 <input type="text" name="fur" placeholder="Enter fur" style="width:300px;height:30px;
89 border: 2px solid #4CAF50; border-radius:3px;background:transparent;" required >
90 <br><br>
91 <input type="number" name="cost" placeholder="Enter cost" style="width:100%;height:30px;
92 border: 2px solid #4CAF50; border-radius:3px;background:transparent;" min="0" required >
93 <br><br>
94 <input type="submit" name="submit" value="update" style="width:100%;height:30px;
95 border: 2px solid #4CAF50; border-radius:3px;cursor:pointer;background-color: #4CAF50" > 
96 </fieldset>
97 </form>
98
99 </body>
100 </html>
101 <?php
102 if(isset($_POST["submit"]))
103 {
104 // define variables and set to empty values
105 $servername = "localhost";
106 $username = "root";
107 $password = "";
108 $dbname = "Petshop_management";
109
110 // Create connection
111 $conn = new mysqli($servername, $username, $password, $dbname);
112 // Check connection
113 if ($conn->connect_error) {
114 die("Connection failed: " . $conn->connect_error);
115 }
116 //echo " CONNECTION ESTABLISHED \r\n";
117 //echo " INSERTION IN PROCESS";
118 $id = $_POST["id"];
119 $category = $_POST["category"];
120 $breed= $_POST["breed"];
121 $weight = $_POST["weight"];
122 $height = $_POST["height"];
123 $age = $_POST["age"];
124 $fur= $_POST["fur"];
125 $cost = $_POST["cost"];
126
127 $Query2="select count(*) from pets where pet_id='$id'";
128 $Execute = mysqli_query($conn,$Query2);
129 $count = mysqli_fetch_row($Execute);
130
131 if($count[0]==1)
132 {
133 $sql = "UPDATE pets SET pet_category='$category' ,cost='$cost' WHERE pet_id='$id';
134 UPDATE animals SET breed='$breed',weight='$weight',height='$height',age='$age',fur='$fur' WHERE pet_id='$id'";
135 if ($conn->multi_query($sql) == TRUE) {
136 echo'<div>
137 <h1 style="color:#f2f2f2;font-size:20px; font-family: "Roboto", sans-serif;margin:auto;">'
138 .$id. ' updated successfully</h1>
139 </div>';
140 } else {
141 echo "Error: " . $sql . "<br>" . $conn->error;
142 }
143 }
144 else{
145 echo '<div>
146 <h1 style="color:#f2f2f2;font-size:30px; font-family: "Roboto", sans-serif;margin:auto;">Given pet_id not found</h1>
147 </div>';
148 }
149
150
151 $conn->close();
152 }
153
154 ?>